﻿package Naruto{
	import flash.display.Stage;
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import Naruto.Bloods.*;
	
	public class ObjectHitTest extends Sprite{
		private var objarr:Array;
		private var enemyarr:Array;
		private var aMe:Naruto;
		private var testtimer:Timer;
		
		public function ObjectHitTest(){}
		
		public function getflystestobj(enemystestobj,me,flystestobj):void{	//获取要检测的对象 ，参数(敌人队列,主角,伤敌飞镖队列)
			objarr = flystestobj;
			enemyarr = enemystestobj;
			aMe = me;
		}
		//普通敌人飞镖碰撞检测
		public function flysobjtesting(stage:Stage,event:Event,_enemys:Array,_flystestobj:Array,appStart:Start):void{
			for( var i = 0; i < objarr.length; i++){
				var spriteA = objarr[i];
				if(spriteA == null)
					continue;
				for( var j = 0; j < enemyarr.length; j++){
					var spriteB = enemyarr[j];
					if(spriteB == null)
					    continue;
					if(_enemys[j].getStatus()==0)	//已经死了
						continue;
					if(spriteA.hitTestObject(spriteB)){
						//var now = new Date();
						//trace("pengdaole: " + now.toString());
						//trace(enemyarr[j]);
						
						appStart._sound1.Play();
						spriteB.gotoAndPlay("start");
						_enemys[j].setStatus(0);		//将敌人状态变为死亡
						if(_flystestobj[i]){
							if(stage.contains(_flystestobj[i])){			//移除飞镖（接触身体后飞镖消失）
								stage.removeChild(_flystestobj[i]);
								objarr[i] = null;
								_flystestobj[i] = null;
							}
						}
					}
				}
			}
		}
		//BOSS飞镖碰撞检测
		public function flysobjtesting2(stage:Stage,event:Event,_Zabuza:Zabuza,_flystestobj:Array,blood:Blood,appStart:Start):void{
			for( var i = 0; i < objarr.length; i++){
				var spriteA = objarr[i];
				if(spriteA == null)
					continue;
				
				if(_Zabuza != null){	//还活着
					var spriteB = _Zabuza.getme();
				}else{
					continue;
				}
				if( (_Zabuza.getStatus()==0)||(_Zabuza.getIsHided()==true) )	//已经死了或者处于雾隐状态
					continue;
				if(spriteA.hitTestObject(spriteB)){
					//trace(enemyarr[j]);
					
					appStart._sound1.Play();
					//动画
//					trace("再不斩伤血了");
					_Zabuza.hurtMe(blood,0);	//参数2:module，0为最低级别
					if(_Zabuza.getHealth()<=0){	//Boss挂了
						_Zabuza.setStatus(0);	//将再不斩状态变为死亡
					}					
					if(stage.contains(_flystestobj[i])){			//移除飞镖（接触身体后飞镖消失）
						stage.removeChild(_flystestobj[i]);
						_flystestobj[i] = null;
					}
				}
				
			}
		}
		
		//主角受伤碰撞检测
		public function flysHurtMeTest(stage:Stage,event:Event,_me,_flyhurtmeobj:Array,blood:Blood):void{
			for( var i = 0; i < _flyhurtmeobj.length; i++){
				var spriteA = _flyhurtmeobj[i];
				var spriteB = aMe.getme();
				if(spriteA == null)
					continue;
				if(spriteB == null)
					continue;
				if(spriteA.hitTestObject(spriteB)){
					//trace("hurting me!");
					aMe.hurtMe(blood,1);
					//me.setStatus(0);		//将敌人状态变为死亡
					if(stage.contains(_flyhurtmeobj[i])){			//移除飞镖（接触身体后飞镖消失）
						stage.removeChild(_flyhurtmeobj[i]);
						_flyhurtmeobj[i] = null;
					}
				}
			}
		}
		
		//主角被技能伤碰撞检测
		public function skillHurtMeTest(stage:Stage,event:Event,_me,skillsHurtMeObj:Array,blood:Blood):void{
			for( var i = 0; i < skillsHurtMeObj.length; i++){
				var spriteA = skillsHurtMeObj[i];
				var spriteB = aMe.getme();
				if(spriteA == null)
					continue;
				if(spriteB == null)
					continue;
				if(spriteA.hitTestObject(spriteB)){
					//trace("hurting me!");
					aMe.hurtMe(blood,2);
					//me.setStatus(0);		//将我状态变为死亡
				}
			}
		}
	
	}
}